package com.jungle.sp.daily.feature.d2_record_pattern;

/**
 * @author Jungle
 * @create 2024-07-14 6:53
 */
public class Demo {
    public static void main(String[] args) {
        Circle circle = new Circle(5);
        // System.out.println(STR."半径==>\{circle.radius()}");
        // Double area = getArea(new Circle(5));
        // Double area = getArea(new Rectangle(10, 10));
        Double area = getArea(new Square(10,10));
        System.out.printf("%.2f%n", area);
    }

    /**
     * Record Pattern的使用
     */
    public static Double getArea(Shape shape) {
        return switch (shape) {
            case Rectangle(double length, double width) -> length * width;
            case Circle(double radius) -> Math.PI * radius * radius;
            case Square(_, _) -> 0d;
            case null -> null;
            default -> throw new IllegalStateException("Unexpected value: " + shape);
        };
    }
}


